/* GUI CONVERTED from reoptre.p (converter v1.75) Sat Aug 12 23:07:50 2000 */
/* reoptre.p - POST SCRAP COSTS TO GENERAL LEDGER                       */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/*F0PN*/ /*V8:ConvertMode=Maintenance                                   */
/*N014*/ /*V8:RunMode=Character,Windows                                 */
/* REVISION: 7.3      LAST MODIFIED: 02/22/93   BY: emb *G760*          */
/* REVISION: 8.5      LAST MODIFIED: 12/05/95   BY: sxb *J053*          */
/* REVISION: 8.6      LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan   */
/* REVISION: 9.1      LAST MODIFIED: 10/01/99   BY: *N014* Patti Gaultney */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KP* myb            */




         {mfdeclre.i}

         define shared variable op_recno as recid.
         define shared variable wr_recno as recid.
         define shared variable wc_recno as recid.

         define new shared variable sf_entity like en_entity.
         define new shared variable ref like glt_ref.
         define new shared variable sf_cr_acct like dpt_lbr_acct.
         define new shared variable sf_dr_acct like dpt_lbr_acct.
/*N014*/ define new shared variable sf_cr_sub  like dpt_lbr_sub.
/*N014*/ define new shared variable sf_dr_sub  like dpt_lbr_sub.
         define new shared variable sf_cr_cc like dpt_lbr_cc.
         define new shared variable sf_dr_cc like dpt_lbr_cc.
         define new shared variable sf_gl_amt like glt_amt.
         define new shared variable opgltype like opgl_type.

         define variable sf_scrp_acct like gl_scrp_acct.
         define variable sf_wip_acct like dpt_lbr_acct.
/*N014*/ define variable sf_scrp_sub  like gl_scrp_sub.
/*N014*/ define variable sf_wip_sub  like dpt_lbr_sub.
         define variable sf_scrp_cc like gl_scrp_cc.
         define variable sf_wip_cc like dpt_lbr_cc.
         define variable stdrun like op_act_run.
         define variable stdbdn like wc_lbr_rate.
         define variable actbdn like wc_lbr_rate.
         define variable stdamt like sf_gl_amt.
         define variable actamt like sf_gl_amt.
         define variable rtevar like sf_gl_amt.
         define variable usevar like sf_gl_amt.
         define variable setuppay like wc_setup_rte.
         define variable glx_mthd like cs_method.
         define variable glx_set like cs_set.
         define variable cur_mthd like cs_method.
         define variable cur_set like cs_set.

         define variable ord_qty like pt_ord_qty no-undo.
         define variable routing as character no-undo.
         define variable bom_code as character no-undo.

         find wr_route no-lock where recid(wr_route) = wr_recno.
         find op_hist no-lock where recid(op_hist) = op_recno.

         find first gl_ctrl no-lock.

/*N014*/ assign
             sf_scrp_acct = gl_scrp_acct
/*N014*/     sf_scrp_sub  = gl_scrp_sub
             sf_scrp_cc   = gl_scrp_cc
             sf_wip_acct  = gl_wip_acct
/*N014*/     sf_wip_sub   = gl_wip_sub
             sf_wip_cc    = gl_wip_cc
             sf_entity    = glentity.

         find pt_mstr no-lock where pt_part = op_part no-error.
         if available pt_mstr then do:
            find pl_mstr no-lock where pl_prod_line = pt_prod_line no-error.
            if available pl_mstr and pl_scrp_acct > "" then
            assign sf_scrp_acct = pl_scrp_acct
/*N014*/           sf_scrp_sub  = pl_scrp_sub
                   sf_scrp_cc   = pl_scrp_cc.
            find pld_det no-lock where pld_prodline = pt_prod_line
            and pld_site = op_site and pld_loc = "" no-error.
            if available pld_det and pld_scrpacct > "" then
            assign sf_scrp_acct = pld_scrpacct
/*N014*/           sf_scrp_sub  = pld_scrp_sub
/*N014*            sf_scrp_cc   = pl_scrp_cc.                         */
/*N014*/           sf_scrp_cc   = pld_scrp_cc.

         end.

         routing = op_part.
         bom_code = op_part.

         find wo_mstr where wo_nbr = op_wo_nbr
         and wo_lot = op_wo_lot no-error.
         if available wo_mstr then do:
            if wo_acct <> ""
            then assign sf_wip_acct = wo_acct
/*N014*/                sf_wip_sub  = wo_sub
                        sf_wip_cc   = wo_cc.
            if wo_routing > "" then routing = wo_routing.
            if wo_bom_code > "" then bom_code = wo_bom_code.

            find si_mstr where si_site = wo_site no-lock no-error.
            sf_entity = si_entity.

            /* DETERMINE COSTING METHOD */
            {gprun.i ""csavg01.p"" "(input wo_part,
                                     input wo_site,
                                     output glx_set,
                                     output glx_mthd,
                                     output cur_set,
                                     output cur_mthd)"
            }
/*GUI*/ if global-beam-me-up then undo, leave.

            if glx_mthd = "AVG" then wo_var = no.
         end.

         /* THE VARIANCES CALCULATED BELOW ARE SET UP AS
         (ACTUAL - STANDARD) --> DR   VARIANCE    (POSITIVE VALUE = UNFAVORABLE)
                                 CR   WIP
            THE FULL POSTING TO WIP IS:
                                 WIP        LABOR/BURDEN     VARIANCE
                            ======+=======  ======+======  ======+======
               LABOR/BURDEN   ACT |               | ACT          |
               VARIANCE           |ACT-STD        |       ACT-STD|
                            ======+=======  ======+======  ======+======
                              STD |               | ACT   ACT-STD|
         */

         rtevar = 0.
         usevar = 0.
         stdamt = 0.

         find iro_det no-lock where
         iro_part = bom_code
         and iro_site = wo_site
         and iro_cost_set = glx_set
         and iro_routing = routing
         and iro_op = op_wo_op no-error.
         if not available iro_det then do:
            ord_qty = 1.
            find ptp_det no-lock where ptp_part = wo_part
            and ptp_site = wo_site no-error.
            if available ptp_det then do:
               if ptp_ord_qty <> 0 then ord_qty = ptp_ord_qty.
            end.
            else do:
               find pt_mstr no-lock where pt_part = wo_part no-error.
               if available pt_mstr and pt_ord_qty <> 0
               then ord_qty = pt_ord_qty.
            end.

/*J053*/    /* CALCULATE & UPDATE ROUTING COSTS */
/*J053*/    /* REFORMATTED TO QAD STANDARDS */
            {gprun.i ""rwroru1a.p"" "(input wo_site,
                                      input glx_set,
                                      input routing,
                                      input bom_code,
                                      input ord_qty,
                                      input op_date,
                                      input yes)"}
/*GUI*/ if global-beam-me-up then undo, leave.


            find iro_det no-lock where iro_part = bom_code
            and iro_site = wo_site
            and iro_cost_set = glx_set
            and iro_routing = routing
            and iro_op = op_wo_op no-error.
         end.

         if available iro_det then
/*J053*/ do:
            sf_gl_amt = iro_cost_tot * op_qty_comp.
/*J053*/    /* ROUND AMOUNT PER BASE CURRENCY PRECISION */
/*J053*/    {gprun.i ""gpcurrnd.p"" "(input-output sf_gl_amt,
                                      input gl_rnd_mthd)"}
/*GUI*/ if global-beam-me-up then undo, leave.


/*N014*/    assign
                opgltype   = "SCRAP"              /* OPERATION SCRAP */
                sf_cr_acct = sf_wip_acct
/*N014*/        sf_cr_sub  = sf_wip_sub
                sf_cr_cc   = sf_wip_cc
                sf_dr_acct = sf_scrp_acct
/*N014*/        sf_dr_sub  = sf_scrp_sub
                sf_dr_cc   = sf_scrp_cc.
            {gprun.i ""sfopgl.p""}
/*GUI*/ if global-beam-me-up then undo, leave.


            wo_wip_tot = wo_wip_tot - sf_gl_amt.
/*J053*/ end. /* IF AVAILABLE IRO_DET */
